﻿<template>
  <div class="profile-page">
    <!-- 页面头部 -->
    <div class="page-header">
      <h1 class="page-title">个人中心</h1>
      <p class="page-subtitle">管理您的个人信息和账户设置</p>
    </div>

    <div class="profile-layout">
      <!-- 左侧用户信息卡片 -->
      <UserInfoCard :user-info="userInfo" @avatar-uploaded="handleAvatarUploaded" />

      <!-- 右侧设置面板 -->
      <div class="settings-card">
        <div class="card-header">
          <h3 class="card-title">账户设置</h3>
          <p class="card-subtitle">管理您的安全设置和第三方账号</p>
        </div>

        <!-- 安全设置 -->
        <div class="settings-section">
          <SecuritySettings @password-changed="handlePasswordChanged" />
        </div>

        <!-- 登录设备追踪 -->
        <div class="settings-section">
          <LoginDevices />
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { computed } from "vue"
import { useUsersStore } from "@/stores/modules/user"
import UserInfoCard from "./components/userInfoCard.vue"
import SecuritySettings from "./components/securitySettings.vue"
import LoginDevices from "./components/loginDevices/index.vue"

const userStore = useUsersStore()

// 用户信息
const userInfo = computed(() => userStore.userInfo || {})

// 处理头像上传成功
const handleAvatarUploaded = async avatarUrl => {
  if (userStore.userInfo) {
    userStore.userInfo.avatar = avatarUrl
    const { secureStorage } = await import("@/utils/core/storage")
    secureStorage.setItem("userInfo", userStore.userInfo)
  }
}

// 处理密码修改成功
const handlePasswordChanged = () => {
  // 密码修改成功，暂无额外处理
}
</script>

<style lang="scss" scoped>
@use "@/styles/base/variables" as *;
@use "@/styles/base/mixins" as *;

.profile-page {
  min-height: 100vh;
  background: $bg-color-layout;
  padding: 2rem 0;
}

.page-header {
  max-width: 1200px;
  margin: 0 auto 2rem;
  padding: 0 1.5rem;
  text-align: center;

  .page-title {
    font-size: 2rem;
    font-weight: 600;
    color: $color-text-primary;
    margin: 0 0 0.5rem 0;
    line-height: 1.2;
  }

  .page-subtitle {
    font-size: 1rem;
    color: $color-text-secondary;
    margin: 0;
    line-height: 1.5;
  }
}

.profile-layout {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 1.5rem;
  display: grid;
  grid-template-columns: 380px 1fr;
  gap: 2rem;
  align-items: start;
}

.settings-card {
  @include theme-card;
  border-radius: 12px;
  overflow: hidden;
  transition: all 0.2s ease;

  &:hover {
    transform: translateY(-1px);
    box-shadow: $box-shadow-base;
  }

  .card-header {
    background: $bg-color-hover;
    border-bottom: 1px solid $border-color-lighter;
    padding: 1.25rem;
    text-align: center;

    .card-title {
      font-size: 1.1rem;
      font-weight: 600;
      margin: 0 0 0.25rem 0;
    }

    .card-subtitle {
      font-size: 0.85rem;
      opacity: 0.9;
      margin: 0;
    }
  }

  .settings-section {
    padding: 1.25rem;

    &:not(:last-child) {
      border-bottom: 1px solid $border-color-lighter;
    }
  }
}

// 响应式设计
@media (max-width: 768px) {
  .profile-layout {
    grid-template-columns: 1fr;
    gap: 1rem;
    padding: 0 1rem 1rem;
  }

  .page-header {
    padding: 1rem;

    .page-title {
      font-size: 1.5rem;
    }

    .page-subtitle {
      font-size: 0.9rem;
    }
  }
}
</style>
